package com.wl.shop.service.impl;

import com.wl.shop.entity.FieldCategory;
import com.wl.shop.dao.FieldCategoryDao;
import com.wl.shop.service.FieldCategoryService;
import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import java.util.List;

import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wangl
 * @since 2017-06-08
 */
@Service
public class FieldCategoryServiceImpl extends ServiceImpl<FieldCategoryDao, FieldCategory> implements FieldCategoryService {

	@Override
	public Boolean isSameName(String enName,String categroyId) {
		// TODO Auto-generated method stub
		FieldCategory fieldCategory = new FieldCategory();
		fieldCategory.setEnName(enName);
		fieldCategory.setCategoryId(categroyId);
		List<FieldCategory>  list = selectList(new EntityWrapper<FieldCategory>(fieldCategory));
		return list !=null && list.size()>0?true:false;
	}

	@Override
	public int selectMaxSort(String categoryId) {
		// TODO Auto-generated method stub
		
		@SuppressWarnings("unchecked")
		Integer max = (Integer)selectObj(Condition.create().setSqlSelect("max(sort)").where("category_id={0}", categoryId));
		if(max !=null && max !=0){
			return max;
		}else{
			return 0;
		}
	}
	
}
